package com.sanda.androidcourse.strategy.mvp;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.sanda.androidcourse.R;

// Activity 实现 View 接口
public class CalculatorActivity extends AppCompatActivity implements CalculatorView {
    EditText etNum1, etNum2;
    Button btnAdd;
    TextView tvResult;
    CalculatorPresenter presenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_calculator);

        etNum1 = findViewById(R.id.etNum1);
        etNum2 = findViewById(R.id.etNum2);
        btnAdd = findViewById(R.id.btnAdd);
        tvResult = findViewById(R.id.tvResult);

        presenter = new CalculatorPresenter(this);

        btnAdd.setOnClickListener(v -> presenter.onAddClicked());
    }

    @Override
    public int getNum1() {
        return Integer.parseInt(etNum1.getText().toString());
    }

    @Override
    public int getNum2() {
        return Integer.parseInt(etNum2.getText().toString());
    }

    @Override
    public void showResult(int result) {
        tvResult.setText("结果: " + result);
    }
}
